package sy.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.Member;
import sy.pageModel.OrderDoctor;
import sy.service.OrderDoctorServiceI;

@Controller
@RequestMapping("/orderDoctorController")
public class OrderDoctorController extends BaseController {
	
	@Autowired
	private OrderDoctorServiceI orderDoctorService;
	
	@RequestMapping("/datagrid")
	@ResponseBody
	public DataGrid datagrid(OrderDoctor order) throws Exception {
		return orderDoctorService.datagrid(order);
	}
	
	@RequestMapping("/datagrid/accepted")
	@ResponseBody
	public DataGrid datagridForAccepted(OrderDoctor order) throws Exception {
		return orderDoctorService.datagridForAccepted(order);
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public Json add(OrderDoctor order, HttpSession session) {
		Json j = new Json();
		try {
			OrderDoctor result = orderDoctorService.add(order);
			j.setSuccess(true);
			j.setMsg("添加成功！");
			j.setObj(result);
			
			//add log
			logUserAction(session, "/orderDoctorController/add", result.toString());
			
		} catch (Exception e) {
			j.setMsg("添加失败：" + e.getMessage());
		}
		return j;
	}
	
	@RequestMapping("/edit")
	@ResponseBody
	public Json edit_save(OrderDoctor order, HttpSession session) {
		Json j = new Json();
		try {
			OrderDoctor result = orderDoctorService.editOrder(order);
			j.setSuccess(true);
			j.setMsg("保存成功！");
			logUserAction(session, "/orderDoctorController/edit", result.toString());
		} catch (Exception e) {
			j.setMsg("保存失败：" + e.getMessage());
		}
		return j;
	}

	@RequestMapping("/edit_ok")
	@ResponseBody
	public Json edit_ok(OrderDoctor order, HttpSession session) {
		Json j = new Json();
		try {
			OrderDoctor result = orderDoctorService.edit(order);
			j.setSuccess(true);
			j.setMsg("修改成功！");
			logUserAction(session, "/orderDoctorController/edit_ok", result.toString());
		} catch (Exception e) {
			j.setMsg("修改失败：" + e.getMessage());
		}
		return j;
	}

	@RequestMapping("/cancel")
	@ResponseBody
	public Json cancel(OrderDoctor order, HttpSession session) {
		Json j = new Json();
		try {
			OrderDoctor result = orderDoctorService.editOrderStatus(order);
			j.setSuccess(true);
			j.setMsg("取消成功！");
			logUserAction(session, "/orderDoctorController/cancel", result.toString());
		} catch (Exception e) {
			j.setMsg("取消失败：" + e.getMessage());
		}
		return j;
	}

	@RequestMapping("/addDetails")
	@ResponseBody
	public Json addDetails(OrderDoctor order, HttpSession session) {
		Json j = new Json();
		try {
			OrderDoctor result = orderDoctorService.addDetails(order);
			j.setSuccess(true);
			j.setMsg("生成详单成功！");
			logUserAction(session, "/orderDoctorController/addDetails", result.toString());
			
		} catch (Exception e) {
			j.setMsg("生成详单失败：" + e.getMessage());
		}
		return j;
	}

}
